﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Test - Open API Control Panel
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    [Get] [<%= Html.ActionLink("Post","PostTest","API") %>]
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td valign="top">
                <% Html.BeginForm(); %>
                <fieldset title="Create Request URL">
                    <legend>Create Request URL</legend>
                    <div class="editor-label">
                        API URL:
                    </div>
                    <div class="editor-field">
                        <% =Html.TextBox("txtAPI_URL", ViewData["API_URL"], new { @style = "width:350px" })%>
                    </div>
                    <div class="editor-label">
                        API Method:
                    </div>
                    <div class="editor-field">
                        <% =Html.DropDownList("ddlAPI_METHOD", ViewData["API_METHOD"] as SelectList, new { @style = "width:350px", onchange = "this.form.submit();" })%>
                    </div>
                </fieldset>
                <%if (!string.IsNullOrEmpty(ViewData["SELECTED_METHOD"].ToString()))
                  {
                %>
                <fieldset title="Un Sign Arguments">
                    <legend>Un Sign Arguments</legend>
                    <%
                        foreach (ArgumentInfo unArgument in ViewData["UnSignArgumets"] as ArrayList)
                        {
                    %>
                    <div class="editor-label">
                        <%=unArgument.Name %>:
                    </div>
                    <div class="editor-field">
                        <% =Html.TextBox( unArgument.Name, unArgument.Value, new { @style = "width:250px" })%>
                    </div>
                    <%
                        }                          
                    %>
                </fieldset>
                <fieldset title="Un Sign Arguments">
                    <legend>Sign Arguments</legend>
                    <%
                        foreach (ArgumentInfo argument in ViewData["SignArgumets"] as ArrayList)
                        {
                    %>
                    <div class="editor-label">
                        <%=argument.Name%>:
                    </div>
                    <div class="editor-field">
                        <% =Html.TextBox( argument.Name, argument.Value, new { @style = "width:250px" })%>
                    </div>
                    <%
                        }                          
                    %>
                </fieldset>
                <fieldset title="API Secret">
                    <legend>API Secret</legend>
                    <%
                        ArgumentInfo api_secret_argument = ViewData["API_SECRET_ARGUMENT"] as ArgumentInfo;
                        if (api_secret_argument != null)
                        {
                    %>
                    <div class="editor-label">
                        <%=api_secret_argument.Name %>:
                    </div>
                    <div class="editor-field">
                        <% =Html.TextBox("txtAPI_SECRET", api_secret_argument.Value, new { @style = "width:250px" })%>
                    </div>
                    <%
                        } %>
                </fieldset>
                <%
                    } 
                %>
                <p>
                    <input type="submit" id="btnCreateRequestURL" name="btnCreateRequestURL" value="Create Request URL" />
                </p>
                <% Html.EndForm(); %>
            </td>
            <td valign="top">
                <fieldset title="Request URL">
                    <legend>Request URL</legend>
                    <div class="editor-label">
                        Request URL:
                    </div>
                    <div class="editor-field">
                        <% =Html.TextArea("txtRequestURL", ViewData["URL"].ToString(), new { @style = "width:600px; height:100px;",@disabled="disabled" })%>
                    </div>
                    <div class="editor-field">
                        [<a href="<%=ViewData["URL"].ToString() %>" class="nyroModal" target="_blank">Ajax POP
                            Request URL</a>]
                    </div>
                </fieldset>
                <p>
                    <input type="submit" id="btnSubmitRequestURL" name="btnSubmitRequestURL" value="Ajax Submit Request URL" />
                </p>
                <fieldset title="Request Result">
                    <legend>Request Result</legend>
                    <div class="editor-label">
                        请Copy以下结果到记事本备用:
                    </div>
                    <div class="editor-field">
                        <fieldset title="XML Result" style="background-color: #faf496; width: 600px;">
                            <span id="labelRequestResult" name="labelRequestResult"></span>
                        </fieldset>
                    </div>
                </fieldset>
            </td>
        </tr>
    </table>

    <script type="text/javascript" language="javascript">

        //json: 提交请求令牌
        $().ready(function() {
            $("#btnSubmitRequestURL").click(function() {

                var request_url = $('#txtRequestURL').val();

                $("#labelRequestResult").text("Loading......");
                $("input[name='btnSubmitRequestURL']")[0].disabled = "disabled";
                $("input[name='btnSubmitRequestURL']")[0].value = "Ajax Submit Request URL...";

                $.post("/API/AjaxSubmitRequest?" + new Date(), {
                    Action: "post",
                    request_url: request_url
                }, function(result) {
                    if (result.FLAG) {
                        $("#labelRequestResult").text(result.DESC);
                        $("input[name='btnSubmitRequestURL']")[0].disabled = "";
                        $("input[name='btnSubmitRequestURL']")[0].value = "Ajax Submit Request URL";
                    }
                    else {
                        $("#labelRequestResult").text(result.DESC);
                        $("input[name='btnSubmitRequestURL']")[0].disabled = "";
                        $("input[name='btnSubmitRequestURL']")[0].value = "Ajax Submit Request URL";
                    }
                })
            })
        })
        

    </script>

    <script type="text/javascript">
        $(function() {
            $.nyroModalSettings({ width: 780 });
        });
    </script>

</asp:Content>
